
package openkeygenerator;

import java.util.Random;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;

/**
 *
 * @author postmanisonline
 */
public class Methods
{
    /*
     * generates the a new key of the length "wantedKeyLength"
     */
    public static String generateKey(int wantedKeyLength)
    {
        String generatedKeyString = "";

        for (int i=0; i < wantedKeyLength; i++)
        {
            //hold the generated chars in number- / letter-range
            int randomFigure = -1;

            //cases: not a character, not an uppercase letter, not a lowercase letter
            while(true)
            {
                randomFigure = new Integer(new Random().nextInt(127));

                if((randomFigure >= 48 && randomFigure <= 57) || (randomFigure >= 65 && randomFigure <= 90) || (randomFigure >= 97 && randomFigure <= 122))
                {
                    break;
                }
            }
            char tmp = (char) randomFigure;
            generatedKeyString = generatedKeyString.concat((new Character(tmp)).toString());
        }

        return generatedKeyString;
    }

}
